﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Page>" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Import Namespace="Buffalo.Lib.Common" %>
<%@ Import Namespace="Buffalo.Tourism.DAL" %>
<%@ Import Namespace="Buffalo.Tourism.DAL.Models" %>
<%@ Import Namespace="Buffalo.Tourism.Enum" %>
<%@ Import Namespace="Buffalo.Web.Areas.Tourism" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>StatisticReport</title>
    <script type="text/javascript">
        var successHandler = function (form, action) {
            if (action.extraParams && action.extraParams.ReportFile) {
                OpenReportViewHandler(action.extraParams.ReportFile);
            }
        };

        function OpenReportViewHandler(reportFile) {
            var win = ReportViewWindow;
            win.autoLoad.params.ReportFile = reportFile;
            win.setTitle('Statistic report');
            win.show();
        }
        function GetData() {
            dsTourCode.reload();
            dsArea.reload();

            Ext.Msg.show({
                title: "Info",
                msg: "Done!",
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.INFO
            });
        }
    </script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>

    <ext:Store ID="dsTourCode" runat="server" AutoLoad="false">
        <Proxy>
            <ext:HttpProxy Url="/Tourism/TourProgram/GetShortListTour/" />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="ID" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="ID" />
                    <ext:RecordField Name="TourCode" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="limit" Value="15" Mode="Raw" />
            <ext:Parameter Name="fromDate" Value="#{datFromDate}.getRawValue()" Mode="Raw" />
            <ext:Parameter Name="toDate" Value="#{datToDate}.getRawValue()" Mode="Raw" />
        </BaseParams>
    </ext:Store>
    <ext:Store ID="dsArea" runat="server" AutoLoad="false">
        <Proxy>
            <ext:HttpProxy Url="/Tourism/TourProgram/GetListArea/" />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="Value" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="Value" />
                    <ext:RecordField Name="Text" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="fromDate" Value="#{datFromDate}.getRawValue()" Mode="Raw" />
            <ext:Parameter Name="toDate" Value="#{datToDate}.getRawValue()" Mode="Raw" />
        </BaseParams>
    </ext:Store>

    <ext:Viewport ID="mainViewPort" runat="server" Layout="fit">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Border="false" Layout="fit">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnGenerateReport" runat="server" Text="GenerateReport" Icon="Accept">
                                <DirectEvents>
                                    <Click Timeout="60000" CleanRequest="true" Url="/Tourism/Report/GenerateStatisticReport" FormID="frmStatisticReport"
                                        Method="POST" 
                                        Success="successHandler"
                                        Failure="Ext.Msg.show({
                                                    title:   'Generating report Error',
                                                    msg:     result.errorMessage,
                                                    buttons: Ext.Msg.OK,
                                                    icon:    Ext.MessageBox.ERROR
                                                });">
                                        <EventMask MinDelay="250" />
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:FormPanel ID="FormPanel1" runat="server" FormID="frmStatisticReport" Border="false"
                        Layout="form" BodyBorder="false" >
                        <Items>
                            <ext:DateField ID="datFromDate" runat="server" FieldLabel="StartDate" Width="300" Format="dd-MM-yyyy" />
                            <ext:DateField ID="datToDate" runat="server" FieldLabel="ToDate" Width="300" Format="dd-MM-yyyy" />
                            <ext:ComboBox ID="cboTourCode" runat="server" StoreID="dsTourCode" Editable="true"
                                FieldLabel="TourCode" DisplayField="TourCode" ValueField="ID" TypeAhead="true"
                                Mode="Local" ForceSelection="true" Width="300" TriggerAction="All" SelectOnFocus="true">
                            </ext:ComboBox>
                            <ext:ComboBox ID="cboArea" runat="server" StoreID="dsArea" Editable="true"
                                FieldLabel="Area" TypeAhead="true" DisplayField="Text" ValueField="Value" 
                                Mode="Local" ForceSelection="true" Width="300" TriggerAction="All" SelectOnFocus="true">
                            </ext:ComboBox>

                            <ext:Button ID="btnGetData" runat="server" Text="GetData" >
                                <Listeners>
                                    <Click Handler="GetData();" />
                                </Listeners>
                            </ext:Button>

                        </Items>
                    </ext:FormPanel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    <ext:Window ID="ReportViewWindow" runat="server" Icon="ArrowIn" Width="800" Height="500"
        Hidden="true" Modal="true" Constrain="true">
        <AutoLoad Url="/Tourism/Report/ReportView/" Mode="IFrame" TriggerEvent="show" ReloadOnEvent="true"
            ShowMask="true" MaskMsg="Opening...">
            <Params>
                <ext:Parameter Name="ReportFile" Value="StatisticReport" Mode="Value" />
            </Params>
        </AutoLoad>
    </ext:Window>
</body>
</html>
